package tests;

import static org.junit.Assert.*;

import main.BST;

import org.junit.Before;
import org.junit.Test;


public class BinarySearchTreeTests
{
	private BST tree;

	@Before
	public void initializeTree() 
	{
		tree = new BST();
	}
	
	@Test
	public void ensureThatTreeIsEmptyWhenFirstInitialized()
	{
		assertTrue(tree.getCount() == 0);
	}
	
	@Test
	public void addOneValueToTreeAndCheckifValueWasReallyAdded()
	{
		//tree.insert(new Integer(100));
		//assertTrue(tree.contains(new Integer(100)));
	}
	
	@Test
	public void addValuesToTreeAndCheckIfValuesWereReallyAdded()
	{
		tree.insert(new Integer(549));
		tree.insert(new Integer(914));
		tree.insert(new Integer(301));
		tree.insert(new Integer(777));
		tree.insert(new Integer(210));
		tree.insert(new Integer(57));
		
		
		assertTrue(tree.contains(new Integer(549)));
		assertTrue(tree.contains(new Integer(914)));
		assertTrue(tree.contains(new Integer(301)));
		assertTrue(tree.contains(new Integer(777)));
		assertTrue(tree.contains(new Integer(210)));
		assertTrue(tree.contains(new Integer(57)));
	}
	
	@Test
	public void addSingleValueAndRemoveThatValue()
	{
		
		//Integer current = new Integer(200);
		//tree.insert(current);
		//tree.delete(current);
		//assertFalse(tree.contains(current));
		
	}
	
	@Test
	public void addAFewValuesAndRemoveThoseValues()
	{
		
		Integer value = new Integer(300);
		Integer value2 = new Integer(500);
		Integer value3 = new Integer(450);
		Integer value4 = new Integer(100);
		Integer value5 = new Integer(200);
		Integer value6 = new Integer(60);
		Integer value7 = new Integer(800);
		Integer value8 = new Integer(470);
		
		tree.insert(value);
		tree.insert(value2);
		tree.insert(value3);
		tree.insert(value4);
		tree.insert(value5);
		tree.insert(value6);
		tree.insert(value7);
		tree.insert(value8);
		
		assertTrue(tree.contains(value));
		assertTrue(tree.contains(value2));
		assertTrue(tree.contains(value3));
		assertTrue(tree.contains(value4));
		assertTrue(tree.contains(value5));
		assertTrue(tree.contains(value6));
		assertTrue(tree.contains(value7));
		assertTrue(tree.contains(value8));
		
		tree.delete(value3);
		assertFalse(tree.contains(value3));
		
		tree.delete(value2);
		assertFalse(tree.contains(value2));
		
		assertTrue(tree.contains(value));
		assertTrue(tree.contains(value4));
		assertTrue(tree.contains(value5));
		assertTrue(tree.contains(value6));
		assertTrue(tree.contains(value7));
		assertTrue(tree.contains(value8));
		
		tree.delete(value);
		assertFalse(tree.contains(value)); 
	}
}
